package com.legendshop.openportal.sdk.registry;

import com.legendshop.openportal.sdk.config.provider.DefaultOpenConfigProvider;
import com.legendshop.openportal.sdk.config.provider.OpenConfigProvider;
import com.legendshop.openportal.sdk.exception.OpenClientException;

/**
 * @author jzh
 * @version 1.0.0
 * @title OpenConfigProviderRegistry
 * @date 2024/6/18 9:55
 * @description：开放平台配置提供者注册器
 */
public class OpenConfigProviderRegistry {

    private static final OpenConfigProvider DEFAULT_PROVIDER = new DefaultOpenConfigProvider();
    private static volatile OpenConfigProvider customProvider;

    private OpenConfigProviderRegistry() {}

    public static void registerProvider(final OpenConfigProvider provider) {
        if (provider == null) {
            throw new OpenClientException("customProvider cannot be null");
        }
        customProvider = provider;
    }

    public static OpenConfigProvider getProvider() {
        return customProvider != null ? customProvider : DEFAULT_PROVIDER;
    }
}
